package com.xidian.yunwudemo.service.impl;

import com.xidian.yunwudemo.dto.DataViewInfoDto;
import com.xidian.yunwudemo.mapper.master.DataAdaptiveMapper;
import com.xidian.yunwudemo.mapper.master.DataBioAuthMapper;
import com.xidian.yunwudemo.mapper.master.DataUserAuthMapper;
import com.xidian.yunwudemo.service.DataViewInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class DataViewInfoServiceImpl implements DataViewInfoService {
    @Autowired
    DataAdaptiveMapper dataAdaptiveMapper;
    @Autowired
    DataUserAuthMapper dataUserAuthMapper;
    @Autowired
    DataBioAuthMapper dataBioAuthMapper;

    @Override
    public String[][] getLastAuthRecord() {
        List<DataViewInfoDto> res = new ArrayList<DataViewInfoDto>();
        List<DataViewInfoDto> adaptive = dataAdaptiveMapper.getLastFiveRecord();
        List<DataViewInfoDto> user = dataUserAuthMapper.getLastFiveRecord();
        List<DataViewInfoDto> biology = dataBioAuthMapper.getLastFiveRecord();
        res.addAll(adaptive);
        res.addAll(user);
        res.addAll(biology);
        return dataFormat(res);
    }

    private String[][] dataFormat(List<DataViewInfoDto> sqlRes){
        int sz = sqlRes.size();
        String[][] data = new String[sz][4];
        for(int i = 0; i < sz; i++){
            data[i][0] = sqlRes.get(i).getDataTime();
            data[i][1] = sqlRes.get(i).getAuthWayDesc();
            data[i][2] = sqlRes.get(i).getClientIP();
            data[i][3] = sqlRes.get(i).getAuthResDesc();
        }
        return data;
    }
}
